namespace AdminApiTemplate.Common.Models
{
    public class PagedList<T>
    {
        /// <summary>
        /// 数据
        /// </summary>
        public List<T> Items { get; set; }

        /// <summary>
        /// 页码
        /// </summary>
        public int PageIndex { get; set; }

        /// <summary>
        /// 每页数量
        /// </summary>
        public int PageSize { get; set; }

        /// <summary>
        /// 总条数
        /// </summary>
        public long TotalCount { get; set; }

        /// <summary>
        /// 总页数
        /// </summary>
        public int TotalPages
        {
            get
            {
                var pages = 0;
                if (PageSize > 0)
                {
                    var num = Convert.ToInt32(TotalCount) / PageSize;
                    var mod = Convert.ToInt32(TotalCount) % PageSize;
                    if (mod > 0) {
                        num += 1;
                    }
                    pages = num;
                }
                return pages;
            }
        }

        /// <summary>
        /// 起始页码数
        /// </summary>
        public int IndexFrom { get; set; }

        /// <summary>
        /// 是否有上一页
        /// </summary>
        public bool HasPreviousPage => PageIndex - IndexFrom > 0;

        /// <summary>
        /// 是否还有下一页
        /// </summary>
        public bool HasNextPage => PageIndex - IndexFrom + 1 < TotalPages;
    }
}
